package it.aekidna.cleverplatypus.logging
{
  import mx.logging.ILoggingTarget;
  
  import org.springextensions.actionscript.ioc.factory.IInitializingObject;
  import org.springextensions.actionscript.ioc.factory.config.AbstractFactoryObject;
  import org.springextensions.actionscript.utils.Assert;

  public class LocalConnectionLoggingTargetFactory 
  	extends AbstractFactoryObject 
  	implements IInitializingObject 
  {

    private var _loggingTarget:ILoggingTarget;
    private var _loggingTargetClass:Class;
    public var level:uint = 0;
    public var filters:Array = [];
	public var destination : String;
	
    public function LocalConnectionLoggingTargetFactory() 
    {
      super();
    }

    public override function getObject() : * 
    {
      return _loggingTarget;
    }

    public override function getObjectType() : Class 
    {
      return loggingTargetClass;
    }

    /**
     * Create the logging target after all properties have been set.
     */
    public function afterPropertiesSet() : void 
    {
      _loggingTarget = new loggingTargetClass();
      if (_loggingTarget is LocalConnectionLogTarget) {
        var target : LocalConnectionLogTarget = _loggingTarget as LocalConnectionLogTarget;
        target.destination = destination;
      }
      _loggingTarget.filters = filters;
      _loggingTarget.level = level;
    }

    public function get loggingTargetClass() : Class 
    {
      return _loggingTargetClass;
    }

    public function set loggingTargetClass( value : Class ) : void 
    {
      Assert.notNull(value, "The loggingTargetClass must not be null");
      _loggingTargetClass = value;
    }

  }
}
